<?php

namespace App\Http\Controllers;

use App\Article;
use Carbon\Carbon;
use Illuminate\Http\Request;

use App\Http\Requests;

class articlesControllers extends Controller
{
    public function index(){
        $pages = Article::latest()->get();
//        return 'article page';
//        return $articles;
        return view('articles.index',compact('pages'));
    }
    public function show($id){
        $pages = Article::findOrFail($id);
//        dd($articles);
//        return $articles;
        return view('articles.show',compact('pages'));
    }
    public function create(){
        return view('articles.create');
    }
    public function store(Request $request){
//        dd($request->all());
        //接收post过来的数据
        //存入数据库
        //重定向
        $input= $request->all();
        $input['published_at']=Carbon::now();
        Article::create($input);
        return redirect('articles');
    }

}
